/**
 * VUEshop
 * ============================================================================
 * * 版权所有 2015-2027 深圳搜豹网络科技有限公司，并保留所有权利。
 * 网站地址: http://www.vueshop.com.cn
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
 * 不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
 * $Author: 沈小白 2020-07-22 $
 */<template> 
	<view>
		<view class="container">
			<view class="team_info">
				<view class="team_tab clearfix">
					<block v-for="(item,index) in navTab" :key="index">
						<view @tap="clickTab" class="team_tab_list":class="navindex==item.id?'active':''" :data-current="item.id">{{item.item}}({{item.num}})</view>
					</block>
				</view>
				<view class="prompt">
					<image :src="imgUrl+'distribut/crown@2x.png'" role="img"></image>
					皇冠标志表示该用户为高级会员
				</view>
				<view class="team_details">
					
					<block v-for="(item,index) in teamList" :key="index">
						<!-- 有下级 -->
						<view class="team_details_list wrap"  v-if="item.leaveType==1">
							<image class="header_image" :src="item.head_pic" role="img"></image>
							<view class="user_info">
								<view class="user_name">
									{{item.nickname}}
									<image :src="imgUrl+'distribut/crown@2x.png'" role="img"></image>
								</view>
								<view class="join_time">加入时间：{{item.reg_time}}</view>
								
							</view>
							<view class='user_data'>
								<view class='consume'><text>获佣: + {{item.distribut_money}}</text></view>
								<view class='number'>{{item.lower_sum}}位成员</view>
							</view>
						</view>
						<!-- 无 -->
						<view class="team_details_list wrap" v-else>
							<image class="header_image" :src="item.head_pic" role="img"></image>
							<view class="user_info">
								<view class="user_name">
									{{item.nickname}}
									<image :src="imgUrl+'distribut/team_header3@2x.png'" role="img"></image>
								</view>
								<view class="join_time">加入时间：{{item.reg_time}}</view>
							</view>
							<view class="user_data">
								<view class="consume">
									消费：
									<text>
										￥{{item.goods_price}}
									</text>
								</view>
								<view class="number">{{item.order_count}}笔订单</view>
							</view>
						</view>
					</block>
					
					
					
				</view>
			</view>
		</view>
		<!-- 公共底部 -->
		<distribut-footer :classInfo="classIndex"></distribut-footer>
	</view>
</template>

<script>
	import distributFooter from "@/components/distributFooter/distributFooter.vue";
	import common from "@/common/common.js"; 
	import {getLowerCount,getFirstLowers,getLowers} from "@/api/api.js";
	import config from "@/api/config";
	import {mapState} from "vuex";
	export default {
		data() {
			return {
				imgUrl:config.imgUrl,
				classIndex:1,//0分销 1团队2账户3分销4网店
				navTab:[
					{item:"一级",num:"0",id:0},
					{item:"二级",num:"0",id:1},
					{item:"三级",num:"0",id:2}
				],
				navindex:0,
				total:"",
				teamList:"",//
				params:{
					size:10,
				}
			};
		},
		components:{
			distributFooter
		},
		computed: {
			...mapState(['hasLogin'])
		},
		onShow(){
		
			// this.params.prom_type=6;
			if(this.hasLogin){
				this.getLowerCount();
			}else{
				common.toast("none","请登录",2000)
			}
			
		},
		methods:{
			/*三个等级的下线人数*/
			getLowerCount(){
				getLowerCount().then(res=>{
					console.log(res)
					this.navTab.forEach((i,index)=>{
						this.navTab[0].num=res.first_lower_count
						this.navTab[1].num=res.second_lower_count
						this.navTab[2].num=res.third_lower_count
					})
					this.getFirstLowers(this.params)
				})
			},
			/*第一级下线*/
			getFirstLowers(params){
				getFirstLowers(params).then(res=>{
					console.log(res)
					res.records.forEach((i,index)=>{
						i.leaveType=1;
						let time=common.format(i.reg_time,'yyyy-MM-dd');
						i.reg_time=time;
					})
					this.teamList=res.records;
					this.total=res.total;
				})
			},
			/*二三级*/ 
			getLowers(params){
				getLowers(params).then(res=>{
					res.records.forEach((i,index)=>{
						
						let time=common.format(i.reg_time,'yyyy-MM-dd');
						i.reg_time=time;
					})
					this.teamList=res.records;
					this.total=res.total;
				})
			},
			onReachBottom(){//下拉加载数据
				
				if(this.teamList.length===this.total){
					common.toast("none","加载完了",2000)
					 return false;
				}
				this.params.size+=9;
				if(this.hasLogin){
					if(this.navindex==0){ //第一级
						delete this.params.level;
						this.getFirstLowers(this.params);
					}
					if(this.navindex==1){ //第二级
						this.getLowers(this.params);
					}
					if(this.navindex==2){ //第三级
						this.getLowers(this.params);
					}
					// this.getDistributionOrder(this.params)
				}
				
				
			},
			/*切换*/ 
			clickTab(e){
				console.log(e)
				let index=e.currentTarget.dataset.current
				this.navindex=index;
				
				this.params.size=10;
				if(this.navindex==0){ //第一级
					delete this.params.level;
					this.getFirstLowers(this.params);
				}
				if(this.navindex==1){ //第二级
					this.params.level=2;
					this.getLowers(this.params);
				}
				if(this.navindex==2){ //第三级
					this.params.level=3;
					this.getLowers(this.params);
					
				}
				
			},
		}
	}
</script>

<style lang="scss">
	.clearfix:after {
		content: '.';
		display: block;
		height: 0;
		overflow: hidden;
		visibility: hidden;
		clear: both;
	}

	.wrap {
		width: 100%;
		padding: 0 20rpx;
		box-sizing: border-box
	}

	page {
		background-color: #f5f5f5;
	}

	.show {
		display: block;
	}

	.hidden {
		display: none;
	}

	.team_info .team_tab .team_tab_list {
		float: left;
		height: 88rpx;
		font-size: 30rpx;
		color: #666;
		line-height: 88rpx;
		text-align: center;
		width: 33.3333%;
		box-sizing: border-box;
	}

	.team_info .team_tab .team_tab_list.active {
		color: #2E2E2E;
		font-weight: bold;
	}

	.team_info .prompt {
		height: 70rpx;
		padding-left: 96rpx;
		font-size: 24rpx;
		color: #666;
		line-height: 70rpx;
		background-color: #f9f2d8;
		overflow: hidden;
		position: relative;
	}

	.team_info .prompt image {
		position: absolute;
		left: 54rpx;
		top: 0;
		width: 26rpx;
		height: 24rpx;
		margin-top: 20rpx
	}

	.team_info .team_details .team_details_list {
		background: #fff;
		width: 710rpx;
		height: 140rpx;
		padding-top: 30rpx;
		padding-bottom: 25rpx;
		box-sizing: border-box;
		border-radius: 10rpx;
		margin: 0 auto;
		margin-top: 20rpx;
	}

	.team_info .team_details .team_details_list .header_image {
		float: left;
		height: 80rpx;
		width: 80rpx;
		border-radius: 50%;
	}

	.team_info .team_details .team_details_list .user_info {
		float: left;
		margin-left: 30rpx;
	}

	.team_info .team_details .team_details_list .user_info .user_name {
		display: block;
		color: #1a1a1a;
		font-size: 28rpx;
		height: 38rpx;
		position: relative;
		width: 356rpx;
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap;
	}

	.team_info .team_details .team_details_list .user_info .user_name image {
		position: absolute;
		height: 26rpx;
		width: 24rpx;
		margin-left: 8rpx;
		margin-top: 7rpx
	}

	.team_info .team_details .team_details_list .user_info .join_time {
		margin-top: 5rpx;
		color: #666;
		font-size: 22rpx;
	}

	.team_info .team_details .team_details_list .user_data {
		float: right;
	}

	.team_info .team_details .team_details_list .user_data .consume {
		color: #1a1a1a;
		font-size: 24rpx;
	}

	.team_info .team_details .team_details_list .user_data .consume text {
		font-weight: bold;
		color: #ff3b3b;
	}

	.team_info .team_details .team_details_list .user_data .number {
		display: block;
		color: #666;
		font-size: 22rpx;
		margin-top: 10rpx;
		text-align: right;
	}
</style>
